


HOSTOS := $(shell uname -s | tr A-Z a-z | \
	    sed -e 's/\(cygwin\).*/cygwin/')

HOST_CFLAGS =
HOST_LDFLAGS =

CPPFLAGS =

PLATFORM_LIBS =

#########################################################################
#
# Include the make variables (CC, etc...)
#
AS	= $(CROSS_COMPILE)as
LD	= $(CROSS_COMPILE)ld
CC	= $(CROSS_COMPILE)gcc
CPP	= $(CC) -E
AR	= $(CROSS_COMPILE)ar
NM	= $(CROSS_COMPILE)nm
STRIP	= $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB	= $(CROSS_COMPILE)RANLIB

ifndef CROSS_COMPILE
CROSS_COMPILE =
#CROSS_COMPILE = mingw32-
export	CROSS_COMPILE
endif

BINS	= dnw$(SFX)

OBJS  = src/Engine.o
OBJS  += src/d_box.o
OBJS  += src/dnw.o
OBJS  += src/fileopen.o 
OBJS  += src/font.o
OBJS  += src/rwbulk.o 
OBJS  += src/usbtxrx.o
OBJS  += dnw_rc.o

LIBS	=		/mingw/lib/libcomdlg32.a
LIBS	+=		

#
# Cygwin needs .exe files :-(
#
ifeq ($(HOSTOS),cygwin)
SFX = .exe
HOST_CFLAGS += -D__WIN32__
else
SFX =
endif

# Add GCC lib
#PLATFORM_LIBS += -L $(shell dirname `$(CC) $(CFLAGS) -print-libgcc-file-name`) -lgcc
PLATFORM_LIBS += -lmingw32 -ldnw -lgdi32 -lcomctl32 -lcomdlg32 -lsetupapi

SUBDIRS	=  

#
# Use native tools and options
#
#CPPFLAGS   = -I/usr/include/mingw -I..	-DUSE_HOSTCC
CPPFLAGS   = -I..	-DUSE_HOSTCC
CFLAGS     = $(HOST_CFLAGS) $(CPPFLAGS)
AFLAGS	   = -D__ASSEMBLY__ $(CPPFLAGS)
#CC	   = $(HOSTCC)
#STRIP	   = $(HOSTSTRIP)
MAKEDEPEND = makedepend

RESFILES = src/dnw.rc
RESOURCES=$(RESFILES:%.rcp=%_rc.o)

LIB 	= libdnw.a

all:	dnw$(SFX) $(LIB)

$(LIB):	$(OBJS)
	$(AR) $(ARFLAGS) $@ $(OBJS)

#dnw$(SFX):	$(OBJS)	$(LIBS) $(LDSCRIPT)
dnw$(SFX):	$(LIB) dnw_rc.o
#dnw$(SFX):	src/d_box.o src/dnw.o src/Engine.o src/fileopen.o src/font.o src/rwbulk.o src/usbtxrx.o
#		$(CC)	$(CFLAGS)	$(HOST_LDFLAGS) -L -lcomdlg32 -lcomctl32 -lcrtdll -o $@ $^	
		$(CC) -Wall	-L "." -lmingw32 -ldnw -lgdi32 -lcomctl32 -lcomdlg32 -lsetupapi -o $@ $^ -mwindows
#		$(CC) -Wall	-L "." -lmingw32 -ldnw -lgdi32 -lcomctl32 -lcomdlg32 -lsetupapi -o $@ $^
#		$(STRIP) $@.exe		
		


Engine.o:	src/Engine.cpp
		$(CPP) -g $(CFLAGS) -c $<


dnw.o:	src/dnw.cpp
		$(CPP) -g $(CFLAGS) -c $<


dnw_rc.o: src/dnw.rc
	windres -o $@ src/dnw.rc
			
d_box.o:	src/d_box.cpp
		$(CPP) -g $(CFLAGS) -c $<
		
fileopen.o:	src/fileopen.cpp
		$(CPP) -g $(CFLAGS) -c $<

font.o:	src/font.cpp 
		$(CPP) -g $(CFLAGS) -c $<

rwbulk.o:	src/rwbulk.c
#		$(CC) -c $(CFLAGS) -c $<
		$(CC) -g $(CFLAGS) -c $<
				
usbtxrx.o:	src/usbtxrx.cpp
		$(CPP) -g $(CFLAGS) -c $<
		

.PHONY : clean
clean :
	rm $(OBJS) dnw$(SFX) 
						
#########################################################################

#.depend:	Makefile $(OBJS:.o=.c)
#		$(CC) -M $(HOST_CFLAGS) $(CPPFLAGS) $(OBJS:.o=.c) > $@

#sinclude .depend

#########################################################################
